package org.snail.transport.impl;

import io.netty.channel.Channel;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.util.HashedWheelTimer;
import io.netty.util.Timeout;
import io.netty.util.TimerTask;

import java.util.concurrent.TimeUnit;

/**
 * 断开的时候触发
 * Created by fish on 17/8/26.
 */
@ChannelHandler.Sharable
public class ConnectionWatcher extends ChannelInboundHandlerAdapter {

    private NettyConnector nettyConnector;

    public ConnectionWatcher(NettyConnector nettyConnector){
        this.nettyConnector = nettyConnector;
    }

    @Override
    public void channelActive(ChannelHandlerContext ctx) throws Exception {
        ctx.fireChannelActive();
    }

    @Override
    public void channelInactive(ChannelHandlerContext ctx) throws Exception {
        nettyConnector.connect(nettyConnector.getHost(), nettyConnector.getPort());
        super.channelInactive(ctx);

    }
}
